package com.hch.maker.template;

import cn.hutool.core.util.StrUtil;
import com.hch.maker.meta.Meta;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author 86134
 * @version 1.0
 * @description TODO
 * @date 2024/8/2 21:36
 */

public class TemplateMakerUtils {


    /**
     * 从未分组的文件中异常同名文件
     * @param fileInfoList
     * @return
     */
    public static List<Meta.FileConfigDTO.FilesDTO> removeGroupFilesFromRoot(List<Meta.FileConfigDTO.FilesDTO> fileInfoList){
        List<Meta.FileConfigDTO.FilesDTO> groupFileInfoList = fileInfoList.stream()
                .filter(fileInfo -> StrUtil.isNotBlank(fileInfo.getGroupKey()))
                .collect(Collectors.toList());

        List<Meta.FileConfigDTO.FilesDTO> groupInnerFileInfoList = groupFileInfoList.stream()
                .flatMap(fileInfo -> fileInfo.getFiles().stream())
                .collect(Collectors.toList());

        Set<String> fileInputPathSet = groupInnerFileInfoList.stream()
                .map(fileInfo -> fileInfo.getInputPath())
                .collect(Collectors.toSet());


        return fileInfoList.stream()
                .filter(fileInfo -> !fileInputPathSet.contains(fileInfo))
                .collect(Collectors.toList());
    }
}
